<?php if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=""){?>
<div class="col-md-8"
<div class="main-content" id="main-content">
	<div class="sub-content">
		<div class="top-header products clearfix">
			<div class="pull-left pad">
				<h1>Users List</h1>
			</div>
			<form id="addUserForm" action="" class="form-horizontal" role="form">>
			<div class="product-list-details form-group">
				<label class="control-label">Adding : </label>
				
				<select id="type" name="addUserType" onchange="loadAddUserForm(this.value)" class="form-conntrol">
					<option value="">Select</option>
					<option value="admin">Admin</option>
					<option value="user">User</option>
				</select>
			</div>
			</form>
		</div><br/>
		<p style="color:red"><a href="<? echo $this->Url('transfer-users');?>">Transfers</a></p>
		<div class="product_table">
			
		</div>
	</div>
</div>
</div>
<script>
$(function(){	
	reloadGrid('superadmin');
}); 

function loadAddUserForm( userType )
{
	if( userType == "admin" )
	{
		window.location=BASE_URL+'/users/addadmin?is_first=1';
	}
	else if( userType == "user" )
	{
		window.location=BASE_URL+'/users/adduser?is_first=1';
	}
}

function reloadGrid(userType) {
$('.product_table').html('Please wait loading....');
		if($("#type").val()==''){
			userType='superadmin';
		}else{
			userType=userType;
		}
	$.ajax({
		type:	'GET',
		dataType:'json',
		url:BASE_PATH+'/users/allusers-ajax?userType='+userType,
		success: function(data){
		$('.product_table').html('<table class="table table-bordered" border="1" cellpadding="0" cellspacing="0" width="100%" id="search_results"><thead><tr class="bg_header"><td>SNO</td><td>CompanyName</td><td width="77px;">Status&nbsp;</td><td>Email</td><td>Phone</td><td>Action</td></tr></thead><tbody></tbody></table>');	
		eval(data);
		var oTable = $('#search_results').dataTable( {
					aoColumnDefs: [{bSortable: false,
									aTargets: [ 0 ]
									}],
					"bStateSave": true,
					"bAutoWidth": true,
					"sRowSelect": "multi",
					"sPaginationType": "full_numbers",
					"bProcessing": true,
 					"aaData": data,
					"aoColumns": [
						{ "mData": "sno" },
						{ "mData": "companyname" },
						{ "mData": "status" },
						{ "mData": "email" },
						{ "mData": "phone" },
						{ "mData": "action" }
					] 
				});			
		}
	});
}
function deleteUser(user_id){
	if(confirm("Are you sure you want delete record?")){
		window.location=BASE_URL+"/users/delete-users?user_id="+user_id;					
	}
}
</script>
<?php }else{?>
<script>
	window.location='<? echo $this->Url('home')?>';
</script>
<?php }?>